module.exports = {
	onLoad() {
		// 设置默认的转发参数
		uni.$u.mpShare = {
			title: '', // 默认为小程序名称
			path: '', // 默认为当前页面路径
			imageUrl: '' // 默认为当前页面的截图
		}
	},
	onShow() {
		let pages = getCurrentPages();
		let page = pages[pages.length - 1];
		if (!page) {
			return
		}
		let str = page.$page.fullPath;
		let path = str.split("?")[0];
		let arr = str.split("?")[1] ? str.split("?")[1].split("&") : [];
		let obj = {};
		for (let i of arr) {
			obj[i.split("=")[0]] = i.split("=")[1];
		}
		if (obj.agentid) {
			uni.setStorageSync('agentid', obj.agentid);
		}
		console.log('页面路径', path + uni.$u.queryParams(obj, true, 'indices'));
		obj.share = 'share';
		let userId = uni.getStorageSync('userId');
		if (userId) {
			obj.agentid = userId;
		} else {
			delete obj.agentid
		}
		console.log('分享链接', path + uni.$u.queryParams(obj, true, 'indices'));
		// 设置默认的转发参数
		uni.$u.mpShare = {
			title: '',
			path: path + uni.$u.queryParams(obj, true, 'indices'),
			imageUrl: '',
		}
	},
	onShareAppMessage() {
		return uni.$u.mpShare
	},
	// #ifdef MP-WEIXIN
	onShareTimeline() {
		return uni.$u.mpShare
	},
	// #endif
}
